package com.zkthink.ceres.app.pay.controller;

import com.zkthink.base.R;
import com.zkthink.ceres.pay.callback.service.PayCallBackService;
import com.zkthink.ceres.pay.entity.AliReturnPayBean;
import com.zkthink.ceres.pay.service.PayService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@Slf4j
@Validated
@RestController
@RequestMapping("/pay")
@Api(value = "支付接口", tags = "支付接口")
@AllArgsConstructor
public class PayController {

    private PayCallBackService payCallBackService;
    /**
     * 统一下单支付结果通知回调
     *
     * @param request
     * @return
     */
    @PostMapping("/notify/order")
    @ApiOperation("微信支付通知")
    public String parseOrderNotifyResult(HttpServletRequest request) {
        log.info("开始执行[支付结果通知回调]:[{}]");
        return payCallBackService.handleOrderNotifyCallBack(request);
    }

    @ApiOperation("微信查询订单信息")
    @GetMapping("/wxSelectOrder/{id}")
    public R selectOrder(@PathVariable("id") String id) {
        return payCallBackService.wxSelectOrder(id);
    }

    @PostMapping("/notify/orderaliPay")
    @ApiOperation("支付宝支付通知")
    public String parseOrderNotifyResultaliPay(HttpServletResponse response, AliReturnPayBean returnPay, HttpServletRequest req) {
        return payCallBackService.handleOrderNotifyCallBackaliPay(response, returnPay, req);
    }

    /**
     * 退款结果通知回调
     *
     * @param request
     * @return
     */
    @PostMapping("/notify/refund")
    @ApiOperation("微信退款通知")
    public String parseRefundNotifyResult(HttpServletRequest request) {
        return payCallBackService.handleRefundNotifyCallBack(request);
    }

    @GetMapping("/notify/refundaliPay")
    @ApiOperation("支付宝退款通知")
    public String parseRefundNotifyResultaliPay(HttpServletResponse response, AliReturnPayBean returnPay, HttpServletRequest req) {
        return null;
    }
}
